package com.zhuoshi.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.zhuoshi.entity.Authority;
import com.zhuoshi.entity.Role;
import com.zhuoshi.service.AuthorityService;
import com.zhuoshi.service.RoleService;

@Controller
@RequestMapping("role")
public class RoleController {
	
	@Autowired
	private RoleService roleService;
	
	@Autowired
	private AuthorityService authorityService;
	
	@RequestMapping("selectAllRoleLiu")
	public ModelAndView selectAllRoleLiu() {
		List<Role> roles=roleService.selectAllRoleLiu();
		ModelAndView modelAndndView=new ModelAndView();	
		modelAndndView.addObject("roles", roles);	
		modelAndndView.setViewName("/Admin/roleManager.jsp");
		return modelAndndView;
	}
	
	@RequestMapping(value="selectAllAuthorityByRoleIdLiu")
	public String selectAllAuthorityByRoleIdLiu(HttpServletResponse response,Integer roleid ) {
		List<Authority> authorities=authorityService.selectAllAuthorityByRoleIdLiu(roleid);
		JSONObject json=new JSONObject();
		json.put("authorities", authorities);
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=null;
		try {
			out=response.getWriter();
			out.print(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
